#pragma once
#include "CWindow/CDialogBase.h"
#include "Win32Utils/CIniHelperEx.h"
#include "CMessageDialog.h"
#include <vector>
#include "Common.h"
#include <thread>
#include <functional>

typedef struct _FILE_INFO
{
	bool bChecked = false;
	_tstring strFileName;
	_tstring strFilePath;
	unsigned long long nFileSize = 0;
}FILE_INFO;

class CDlgCombine
	:
	public CDialogBase
{
public:
	CDlgCombine();
	~CDlgCombine();

public:

	dlg_msg LRESULT OnInitDialog(WPARAM wParam, LPARAM lParam);
	dlg_msg LRESULT OnDropFiles(WPARAM wParam, LPARAM lParam);
	dlg_msg LRESULT OnClose(WPARAM wParam, LPARAM lParam);
	dlg_msg LRESULT OnLanguageChange(WPARAM wParam, LPARAM lParam);
	dlg_msg LRESULT OnColor(WPARAM wParam, LPARAM lParam);

	dlg_notify LRESULT OnListViewGetDispInfo(WORD wID, LPNMHDR pNmhdr);
	dlg_notify LRESULT OnListViewDbClick(WORD wID, LPNMHDR pNmhdr);
	dlg_notify LRESULT OnListViewClick(WORD wID, LPNMHDR pNmhdr);
	dlg_notify LRESULT OnListViewColumnClick(WORD wID, LPNMHDR pNmhdr);
	dlg_notify LRESULT OnListViewBeginDrag(WORD wID, LPNMHDR pNmhdr);
	dlg_notify LRESULT OnListViewBeginLabelEdit(WORD wID, LPNMHDR pNmhdr);
	dlg_notify LRESULT OnListViewEndLabelEdit(WORD wID, LPNMHDR pNmhdr);

	dlg_command LRESULT OnMoveUp(WORD wNotify, WORD wID, HWND hWnd);
	dlg_command LRESULT OnMoveDown(WORD wNotify, WORD wID, HWND hWnd);
	dlg_command LRESULT OnMoveTop(WORD wNotify, WORD wID, HWND hWnd);
	dlg_command LRESULT OnMoveBottom(WORD wNotify, WORD wID, HWND hWnd);
	dlg_command LRESULT OnSelectAll(WORD wNotify, WORD wID, HWND hWnd);
	dlg_command LRESULT OnSelectReverse(WORD wNotify, WORD wID, HWND hWnd);
	dlg_command LRESULT OnRemove(WORD wNotify, WORD wID, HWND hWnd);
	dlg_command LRESULT OnClear(WORD wNotify, WORD wID, HWND hWnd);
	dlg_command LRESULT OnCombineFile(WORD wNotify, WORD wID, HWND hWnd);
	dlg_command LRESULT OnOpenFile(WORD wNotify, WORD wID, HWND hWnd);

	dlg_command LRESULT OnLang_zh_cn(WORD wNotify, WORD wID, HWND hWnd);
	dlg_command LRESULT OnLang_en_US(WORD wNotify, WORD wID, HWND hWnd);
public:

	virtual BOOL DialogMessage(LPMSG pMsg);
	virtual BOOL PreTranslateMessage(LPMSG pMsg);

private:
	void InitListView();
	void ListViewMoveItemUp();
	void ListViewMoveItemDown();
	BOOL MoveVectorItemTop(BOOL bInverse);
	void ListViewUpdateVisiableItem();
	void ListViewUpdateChecked();
	void ViewBottomItem();
	bool DoCombineTask();
	bool CombineFile(_tstring strPath, 
		std::function<bool(long long llSize, long long llTotal, long long nFile, long long nTotalFile)> cbProgress = nullptr
	);

	DECLARE_DLG_MESSAGE_MAP()

	HWND m_hList = NULL;
	HBRUSH m_hBrush = NULL;
	std::vector<FILE_INFO> m_fileList;
	LANGID m_langID = 0;
	std::thread m_splitTask;
	CMessageDialog m_msgDlg;
	bool m_bCancel = false;
	bool m_bTaskRunning = false;
	bool m_bQuit = false;
};
